-- http://www.qlcoder.com/task/75d8
local start_arr = { {0,0},{-1,0},{0,-1},{1,-1},{0,1}}
local temp_arr={}
local dest_arr={}
local x
local y
local min_x =0
local min_y =0
local max_x =0
local max_y =0
local count = 0
local i
local j



function loop()
	for _, value in pairs(temp_arr) do
		x = value[1]
		y = value[2]
		if x <= 0 and x < min_x then
			min_x = x 
		elseif x > 0 and x > max_x then
			max_x = x
		end
		
		if y <= 0 and y < min_y then
			min_y = y 
		elseif y > 0 and y > max_y then
			max_y = y
		end
		
	end
	-- print("min_x, max_x",min_x,max_x)
	-- print("min_y,max_y", min_y, max_y)
	local loop_x = 0
	local loop_y = 0
	for loop_x = min_x-1 , max_x+1 do
		for loop_y = min_y-1 , max_y+1 do
			check_is_dead(loop_x, loop_y)
		end
	end
end

function check_is_dead(x,y)
	if x > max_x + 1 or x < min_x - 1 or y < min_y -1 or y > max_y +1 then
		return 
	end
	local point = {}
	local point_temp = {}
	point[1] = x
	point[2] = y
	count = 0
	local i = 0
	local j = 0
	if is_in_map(point) then   --  活着的点
		for i = x - 1, x + 1 do 
			for j = y-1, y + 1 do 
				point_temp[1] = i;
				point_temp[2] = j;
				if is_in_map(point_temp) then	 -- 活着的点
					count = count + 1
				end
			end
		end
		if count >= 3 and count <= 4 then   -- 包含自己 所以加1
			if is_in_dest_map(point) then 
			else
				table.insert(dest_arr,point)
			end
		end
	else                           -- 死点
		for i = x - 1, x + 1 do 
			for j = y-1, y + 1 do 
				point_temp[1] = i;
				point_temp[2] = j;
				if is_in_map(point_temp) then	 -- 活着的点
					count = count + 1
				end
			end
		end
		if count == 3 then
			if is_in_dest_map(point) then 
			else
				table.insert(dest_arr,point)
			end
		end
	end
	
end

function is_in_map(point)
	for _, v in pairs(temp_arr) do
		if v[1] == point[1] and v[2] == point[2] then
			return true
		end
	end
	return false
end

function is_in_dest_map(point)
	for _, vv in pairs(dest_arr) do
		if vv[1] == point[1] and vv[2] == point[2] then
			return true
		end
	end
	return false
end

function main ()
	temp_arr = start_arr
	dest_arr = {}
	diedai = 0
	renkou = 0
	local Max_num = 1000
	for ci = 1 ,Max_num do
		loop()
		if #dest_arr > renkou then
			diedai = ci
			renkou =  #dest_arr
		end
		 print(ci,#dest_arr)
		-- for _,v in pairs (dest_arr) do
			-- print(v[1],v[2])
		-- end
		temp_arr = dest_arr
		dest_arr = {}
	end
	print("max:",diedai, renkou)
end

main()
